package com.hksj.common.log.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hksj.common.log.dto.OperationRecordLogDTO;
import com.hksj.common.log.entity.OperationRecordLog;
import com.hksj.common.log.mapper.OperationRecordLogMapper;
import org.springframework.stereotype.Service;
import com.hksj.common.log.vo.OperationRecordLogVO;

import java.util.List;

/**
 * @author zengke
 * @version 1.0
 * @see OperationRecordLogService
 * @since 2024/3/16 14:34
 */

@Service
public class OperationRecordLogService extends ServiceImpl<OperationRecordLogMapper, OperationRecordLog> {

    /**
     * 新增操作日志
     * @param operationRecord 操作日志对象
     */
    public void createOperationRecord(OperationRecordLog operationRecord){
        super.save(operationRecord);
    }

    public Page<OperationRecordLogVO> queryOperationRecordList(OperationRecordLogDTO dto){

        //创建分页对象
        Page<OperationRecordLogVO> page = new Page<>(dto.getPageNum(),dto.getPageSize());

        //设置禁止sql优化
        page.setOptimizeCountSql(false);

        //调用mapper的分页查询
        List<OperationRecordLogVO> operationRecordList = baseMapper.queryOperationRecordList(page, dto);

        //将分页结果设置到分页对象
        page.setRecords(operationRecordList);

        //返回分页对象
        return page;
    }

}
